#ifndef COMMON_H
#define COMMON_H

#ifndef _UNICODE
#define _UNICODE
#endif
#ifndef UNICODE
#define UNICODE
#endif

#define WIN32_LEAN_AND_MEAN

#include <Windows.h>
#include <tchar.h>
// keep include order
#include <list>
#include <string>
#include <stdexcept>

#if defined _DEBUG && !defined DEBUG
#define DEBUG
#endif

#ifdef DEBUG
const bool debugEnable = true;
#else
const bool debugEnable = false;
#endif

typedef std::wstring WString;

enum Error {
    ERR_OK, // no error
    ERR_LOAD_JVM_DLL,
    ERR_CREATE_JVM,
    ERR_MAIN_CLASS_NOT_FOUND,
    ERR_RUN_MAIN_METHOD
};

class Common final {
  private:
    Common(void);                   // 默认构造函数
    Common(Common const &);         // 拷贝构造函数
    void operator=(Common const &); // 重载赋值运算符
    WString exePath;
    WString exeDir;

  public:
    static Common &getInstance();
    ~Common(void);
    void showMessageBox(bool error, const WString &message);
    void debug(const WString &message);
    bool isFileExists(const WString &filename);
    WString getExePath(); // 获取可执行文件的全路径
    WString getExeDir();  // 获取可执行文件所在目录
    WString getEnvVar(const WString &name);
    std::list<WString> splitString(const WString &text, const TCHAR &delimiter);
    WString trimString(WString &text);
    const std::string wstring2utf8(const WString &text);
    std::list<WString> getCommandLineArgs();
};

#endif // COMMON_H